<?php
namespace common\models;

use yii\db\ActiveRecord;
use yii\behaviors\TimestampBehavior;
use Yii;

/**
 * 经纪人信息数据模型
 * @author CGA
 */
class ARBrokerAmount extends ActiveRecord
{

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%broker_amount}}';
    }

    /**
     * 获取用户信息
     */
    public function getUser()
    {
        return $this->hasOne(ARUser::className(), ['id' => 'uid']);
    }

    /**
     * 获取交易信息
     */
    public function getOrders()
    {
        return $this->hasMany(AROrder::className(), ['broker' => 'uid']);
    }

    /**
     * 获取评分信息
     */
    public function getScoring()
    {
        return $this->hasOne(ARUserScoring::className(), ['uid' => 'uid']);
    }

    /**
     * 获取收款信息
     */
    public function getWallet()
    {
        return $this->hasMany(ARWallet::className(), ['uid' => 'uid']);
    }

    /**
     * 获取信任经纪人信息
     */
    public function getTrust()
    {
        return $this->hasOne(ARTrustBroker::className(), ['broker_id' => 'uid'])->where([ARTrustBroker::tableName().'.uid' => Yii::$app->user->id]);
    }

    /**
     * 获取用户实名信息
     */
    public function getCertificate()
    {
        return $this->hasOne(ARUserCertificate::className(), ['uid' => 'uid']);
    }
}
